<?php
/**
 * User: aka
 * Date: 2018/6/26
 * Time: 16:38
 */

namespace app\backstage\controller;


class Food extends Admin
{
    static private $classification = 'classification_info';
    static private $food = 'food_info';

    private function findClassificationData() : array
    {
        $urlData = $this->getRequestOperation()->getAllRequestParam();
        $classificationData = $this->getDbOperation()->find(self::$classification,['id'=>base64_decode($urlData['id'])]);
        return $classificationData;
    }

    public function classificationListView()
    {
        $classificationData = $this->getDbOperation()->select(self::$classification);
        $treeClassificationData = $this->getDataTree()->tree($classificationData,'classification_name','id');
        return view('classificationList',['classificationData'=>$treeClassificationData]);
    }

    public function classificationAddView()
    {
        return view('classificationAdd');
    }

    public function classificationSubView()
    {
        $classificationData = $this->findClassificationData();
        return view('classificationSub',['classificationData'=>$classificationData]);
    }

    public function classificationEditView()
    {
        $classificationData = $this->findClassificationData();
        return view('classificationEdit',['classificationData'=>$classificationData]);
    }

    public function foodListView()
    {
        $pageNum = $this->getDbOperation()->paginate(self::$food,9);
        $listData = $pageNum->toArray();
        foreach ($listData['data'] as $k => $v)
        {
            $listData['data'][$k]['type'] = '';
            $listData['data'][$k]['type'] = $this->getDbOperation()->fieldFind(self::$classification,['id'=>$v['food_classification']],['classification_name']);
        }
        return view('foodList',['pageNum'=>$pageNum,'listData'=>$listData['data']]);
    }

    public function foodAddView()
    {
        $classificationData = $this->getDbOperation()->whereSelect(self::$classification,['status'=>1]);
        $treeClassificationData = $this->getDataTree()->tree($classificationData,'classification_name','id');
        return view('foodAdd',['classificationData'=>$treeClassificationData]);
    }

    public function foodInfoEditView()
    {
        $urlData = $this->getRequestOperation()->getAllRequestParam();
        $foodData = $this->getDbOperation()->find(self::$food,['id'=>base64_decode($urlData['id'])]);
        $classificationData = $this->getDbOperation()->whereSelect(self::$classification,['status'=>1]);
        $treeClassificationData = $this->getDataTree()->tree($classificationData,'classification_name','id');
        return view('foodInfoEdit',['classificationData'=>$treeClassificationData,'foodData'=>$foodData]);
    }

    public function foodImgEditView()
    {
        $urlData = $this->getRequestOperation()->getAllRequestParam();
        return view('foodImgEdit',['imgId'=>$urlData]);
    }
}